package edu.nf.project.webs.employeeAndCustomerInformation;

import edu.nf.project.entitys.entity.employeeAndCustomerInformation.convention.ShippingAddress;
import edu.nf.project.services.employeeAndCustomerInformation.ShippingAddressService;
import edu.nf.project.services.response.BaseController;
import edu.nf.project.services.response.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author CSY
 * @date 2025 - 06 - 08
 */
@RestController
@RequestMapping("/api/address")
public class ShippingAddressController extends BaseController {
    @Autowired
    private ShippingAddressService shippingAddressService;

    @GetMapping("/list/{uId}")
    public ResultVO<List<ShippingAddress>> listAddressByUserId(@PathVariable int uId) {
        List<ShippingAddress> addressList = shippingAddressService.listAddressByUserId(uId);
        return success(addressList);
    }

    @GetMapping("/{addressId}")
    public ResultVO<ShippingAddress> getAddressByAddressId(@PathVariable int addressId) {
        ShippingAddress address = shippingAddressService.getAddressByAddressId(addressId);
        return success(address);
    }

    @PostMapping
    public ResultVO<String> addAddress(@RequestBody ShippingAddress address) {
        shippingAddressService.addAddress(address);
        return success();
    }

    @PutMapping
    public ResultVO<String> updateAddress(@RequestBody ShippingAddress address) {
        shippingAddressService.updateAddress(address);
        return success();
    }

    @PostMapping("{addressId}")
    public ResultVO<String> deleteAddress(@PathVariable Integer addressId) {
        shippingAddressService.deleteAddress(addressId);
        return success();
    }
}
